//
//  ECRegularExpression.m
//  Edu_iOS
//
//  Created by apple on 2017/9/11.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECRegularExpression.h"

@implementation ECRegularExpression

+(BOOL)isPhoneNumber:(NSString *)patternStr{
    NSString *pattern = @"^1[34578]\\d{9}$";
    NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:nil];
    NSArray *results = [regex matchesInString:patternStr options:0 range:NSMakeRange(0, patternStr.length)];
    return results.count > 0;
}

+(BOOL)detectionIsEmailQualified:(NSString *)patternStr{
    NSString *pattern = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:nil];
    NSArray *results = [regex matchesInString:patternStr options:0 range:NSMakeRange(0, patternStr.length)];
    return results.count > 0;
}

+(BOOL)detectionIsPasswordQualified:(NSString *)patternStr{
//    NSString *pattern = @"^([A-Z]|[a-z]|[0-9]){6,20}$";
//        NSString *pattern = @"^[a-zA-Z0-9]{6,21}$";
//
//    NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:nil];
//    NSArray *results = [regex matchesInString:patternStr options:0 range:NSMakeRange(0, patternStr.length)];
//    return results.count > 0;
    if (patternStr.length < 6 || patternStr.length > 20) {
        return NO;
    }
    return YES;
}

@end
